home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Processes / Launch Me / LaunchMeFRAG.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-15  |  3.2 KB  |  97 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines demonstrating how to launch an application without from a Time
  5. **    Manager task which calls a Notification Manager task.
  6. **
  7. **    by Mark Cookson, and Pete Gontier, Apple Developer Technical Support
  8. **
  9. **    File:    LaunchMeFRAG.c
  10. **
  11. **    Copyright ©1996 Apple Computer, Inc.
  12. **    All rights reserved.
  13. **
  14. **    You may incorporate this sample code into your applications without
  15. **    restriction, though the sample code has been provided "AS IS" and the
  16. **    responsibility for its operation is 100% yours.  However, what you are
  17. **    not permitted to do is to redistribute the source as "Apple Sample
  18. **    Code" after having made changes. If you're going to re-distribute the
  19. **    source, we require that you make it clear in the source that the code
  20. **    was descended from Apple Sample Code, but that you've made changes.
  21. */
  22.  
  23. #include "LaunchMe.h"
  24.  
  25. #ifndef __Assembler__
  26. #    include <Assembler.h>
  27. #endif
  28.  
  29. /*    This function is the Notification Manager task that will be called.
  30.     LaunchApplication() can be called safely from a Notification Manager call, but
  31.     not from a Time Manager task which is why the Time Manager task makes a
  32.     Notification Manager task to launch the application.
  33.  
  34.     This routine removes the notification, and the launch info pointer from
  35.     the system heap and then calls a routine that will remove the code segement
  36.     from the system heap.
  37. */
  38. static pascal Handle NMResponder (NMRecPtr nmrp)
  39. {
  40.     void __Startup__ (void);
  41.  
  42.     MyDelayedLaunchPtr launchInfo = (MyDelayedLaunchPtr) nmrp->nmRefCon;
  43.  
  44.     (void)LaunchApplication (&(launchInfo->launchMe));    // Not much we could do about an error now.
  45.     NMRemove (nmrp);
  46.     DisposePtr ((Ptr)launchInfo);
  47.  
  48.     return RecoverHandle ((Ptr) __Startup__);
  49. }
  50.  
  51. static pascal asm void NMResponderAsm (void)
  52. {
  53.     //
  54.     //    By Pete Gontier
  55.     //
  56.     //    This function takes a parameter on the stack, but we
  57.     //    don't declare it at the C level so the compiler doesn't
  58.     //    know about it. That's fine, as long as we are willing to
  59.     //    do the extra work, and we are.
  60.     //
  61.  
  62.     CLR.L            -(A7)                // NMResponder return value
  63.     MOVE.L            8(A7),-(A7)            // parameter to NM response func
  64.     JSR                NMResponder            // call the real NM task
  65.     MOVE.W            #_DisposeHandle,D0    // _GetTrapAddress parameter
  66.     _GetTrapAddress | newOSTrap
  67.     MOVE.L            A0,A1                // _GetTrapAddress return value
  68.     MOVE.L            (A7)+,A0            // NMResponder return value to DisposeHandle
  69.     MOVE.L            (A7),4(A7)            // copy our return address over our parameter
  70.     ADDQ.L            #4,A7                // dump extra return address
  71.     JMP                (A1)                // "call trap" DisposeHandle
  72.  
  73.     //
  74.     //    All this hackiness has called DisposeHandle such that it will
  75.     //    return to whoever called us; we never get control back, which
  76.     //    is exactly what we want, since we are disposing the handle
  77.     //    which contains our code.
  78.     //
  79. }
  80.  
  81. pascal void main (MyDelayedLaunchPtr passedPtr:__a1)
  82. {
  83.     RmvTime ((QElemPtr) passedPtr);
  84.  
  85.     passedPtr->NMProcRec.qType        = 8;
  86.     passedPtr->NMProcRec.nmMark        = 0;
  87.     passedPtr->NMProcRec.nmIcon        = nil;
  88.     passedPtr->NMProcRec.nmSound    = nil;
  89.     passedPtr->NMProcRec.nmStr        = nil;
  90.     // This is a pointer to our cool clean up routine so that we don't leave an orphaned
  91.     // block of code in the system heap.
  92.     passedPtr->NMProcRec.nmResp        = (NMProcPtr) NMResponderAsm;
  93.     passedPtr->NMProcRec.nmRefCon    = (long)passedPtr;
  94.  
  95.     NMInstall (&passedPtr->NMProcRec);
  96. }
  97.